package com.rd.student.ruanjian.class3.gaochenxi.day0801;

import java.util.ArrayList;
import java.util.Random;

public class Test2 {
   public static void main(String[] args) {
      int min = 0;
      int max = 18;
      Store store = new Store();
      Animal dog = store.getInstance("dog");
      Animal cat = store.getInstance("cat");
      Animal pig = store.getInstance("pig");

      ArrayList<Animal> arrayList = new ArrayList<>();
      for (int i = 0; i < 10; i++) {
         arrayList.add(dog);
      }
      for (int i = 0; i < 5; i++) {
         arrayList.add(cat);
      }
      for (int i = 0; i < 3; i++) {
         arrayList.add(pig);
      }

      int[] arr = new int[2];
      for (int i = 0; i < arr.length; i++) {
         Random random = new Random();
         int randoms = min + random.nextInt(max - min);
         arr[i] = randoms;
         for (int j = 0; j < i; j++) {
            if (arr[j] == arr[i]) {
               i--;
               break;
            }
         }
      }

      for (int i = 0; i < arr.length; i++) {
         Animal animal = arrayList.get(arr[i]);
         Lady lady = new Lady("张", animal);
         lady.myPetEnjoy();
      }
   }
}

abstract class Animal {

   private String name;

   public Animal(String name) {
      this.name = name;
   }

   abstract String enjoy();

   abstract void voice();

   public String getName(Animal animal) {
      return animal.name;
   }
}

class Cat extends Animal {
   private String name;
   private String eyesColor;

   public Cat(String name, String eyesColor) {
      super(name);
      this.eyesColor = eyesColor;
   }

   public String getName() {
      return name;
   }

   @Override
   String enjoy() {
      return "笑了笑，并发出了喵的叫声";
   }

   @Override
   void voice() {
      System.out.println("喵~");
   }
}

class Dog extends Animal {
   private String name;
   private String furColor;

   public Dog(String name, String furColor) {
      super(name);
      this.furColor = furColor;
   }

   public String getName() {
      return name;
   }

   @Override
   String enjoy() {
      return "叫了一下，汪~汪~!";
   }

   @Override
   void voice() {
      System.out.println("汪~汪~!");
   }
}

class Pig extends Animal {

   private String name;
   private String fur;

   public Pig(String name, String fur) {
      super(name);
      this.fur = fur;
   }

   @Override
   String enjoy() {
      return "拱了拱她,它想吃白菜";
   }

   public String getName() {
      return name;
   }

   void voice() {
      System.out.println("JIJIBAO!!!!");
   }
}

class Lady {
   private String name;
   private Animal pet;

   public Lady(String name, Animal pet) {
      this.name = name;
      this.pet = pet;
   }

   public void myPetEnjoy() {
      System.out.println(name + "女士买下" + pet.getName(pet) + ",它看着她,开心地" + pet.enjoy());
   }
}

class Store {
   public Animal getInstance(String str) {
      Animal animal = null;
      if (str.equals("dog")) {
         animal = new Dog("黑子", "Black");
      } else if (str.equals("cat")) {
         animal = new Cat("小白", "Red");
      } else if (str.equals("pig")) {
         animal = new Pig("小花", "pink");
      }
      return animal;
   }
}
